package com.cloudsigns.factorymanager2.engineering.activity;

/**/

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.cloudsigns.factorymanager2.R;

import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

/**
 * 接收维修单
 */
public class ReceiveMaintenanceOrderActivity extends Activity implements View.OnClickListener {
    private RelativeLayout rl_back;
    private TextView tv_title;
    private RelativeLayout rl_project;
    private LinearLayout ll_bottom;
    private TextView tv_receive_people_colon,tv_reception_time_colon;
    private final String TAG = ReceiveMaintenanceOrderActivity.class.getSimpleName();
    private TextView btn_receive_order, btn_back_order;
    private ImageView img_project_select;
    private LinearLayout ll_engineering_info_content;

    private String type;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏
        // 沉浸式状态栏
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
                    );
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN

                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(Color.TRANSPARENT);

        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }
        setContentView(R.layout.layout_receive_maintenance_order);

        init();
    }

    private void init() {
        rl_back = findViewById(R.id.rl_back);
        tv_title = findViewById(R.id.tv_title);
        rl_project = findViewById(R.id.rl_project);
        btn_receive_order = findViewById(R.id.btn_receive_order);
        img_project_select = findViewById(R.id.img_project_select);
        btn_back_order = findViewById(R.id.btn_back_order);
        ll_engineering_info_content = findViewById(R.id.ll_engineering_info_content);
        ll_bottom=findViewById(R.id.ll_bottom);
        tv_receive_people_colon=findViewById(R.id.tv_receive_people_colon);
        tv_reception_time_colon=findViewById(R.id.tv_reception_time_colon);

        tv_title.setText(getResources().getText(R.string.maintenance_order));
        img_project_select.setBackgroundResource(R.mipmap.arrow_down_icon);

        Intent intent=getIntent();
        type=intent.getStringExtra("type");
        if ("BackEngineeringOrderFragment".equals(type)){
            ll_bottom.setVisibility(View.GONE);
            tv_receive_people_colon.setText("退  回  人：");
            tv_reception_time_colon.setText("退回时间：");
        }
        if ("HasBeenReceivedFragment".equals(type)||"EditEngineeringInstallationOrderActivity".equals(type)){
            ll_bottom.setVisibility(View.GONE);
        }
        if ("WattingToReceiveEngineeringOrderFragment".equals(type)){
            ll_bottom.setVisibility(View.VISIBLE);
        }

        rl_back.setOnClickListener(this);
        btn_receive_order.setOnClickListener(this);
        btn_back_order.setOnClickListener(this);
        rl_project.setOnClickListener(this);


    }

    private void receiveOrder() {
        Toast.makeText(this, "接收成功", Toast.LENGTH_SHORT).show();
        btn_receive_order.setClickable(false);
        btn_receive_order.setBackgroundResource(R.mipmap.btn_bg_short_gray);
        btn_back_order.setClickable(false);
        btn_back_order.setBackgroundResource(R.mipmap.btn_bg_short_gray);
    }

    private void backOrder() {
        Toast.makeText(this, "退回成功", Toast.LENGTH_SHORT).show();
        btn_receive_order.setClickable(false);
        btn_receive_order.setBackgroundResource(R.mipmap.btn_bg_short_gray);
        btn_back_order.setClickable(false);
        btn_back_order.setBackgroundResource(R.mipmap.btn_bg_short_gray);
    }

    private void showEngineeringInfoDialog() {
        if (ll_engineering_info_content.getVisibility() == View.VISIBLE) {
            ll_engineering_info_content.setVisibility(View.GONE);
            img_project_select.setBackgroundResource(R.mipmap.arrow_down_icon);
        } else {
            ll_engineering_info_content.setVisibility(View.VISIBLE);
            img_project_select.setBackgroundResource(R.mipmap.arrow_top);
        }
    }


    @Override
    public void onClick(View view) {

        switch (view.getId()) {
            case R.id.rl_back:
                finish();
                break;
            case R.id.btn_receive_order:
                receiveOrder();
                break;
            case R.id.btn_back_order:
                backOrder();
                break;
            case R.id.rl_project:
                showEngineeringInfoDialog();
                break;


        }
    }
}
